package com.zjuee.web.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.dto.common.plan.PlanMaterialDto;
import com.zjuee.service.PlanMaterialService;
import com.zjuee.base.model.common.plan.PlanMaterial;
import com.zjuee.web.ledger.mapper.PlanMaterialMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ding jinli
 * @since 1.0
 */
@Slf4j
@Service
public class PlanMaterialServiceImpl implements PlanMaterialService {
    @Resource
    PlanMaterialMapper planMaterialMapper;


    @Override
    public Long add(PlanMaterial type) {
        int state = planMaterialMapper.insert(type);
        if (1 == state) {
            return type.getId();
        }
        return null;
    }

    @Override
    public boolean delete(Long id, Long validateId) {
        PlanMaterial planMaterial = planMaterialMapper.selectById(id);
        if (validateId.equals(planMaterial.getWpiId())) {
            int type = planMaterialMapper.deleteById(id);
            if (1 == type) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean update(PlanMaterial type) {
        int state = planMaterialMapper.updateById(type);
        if (1 == state) {
            return true;
        }
        return false;
    }

    @Override
    public PlanMaterial selectById(Long id, Long validateId) {
        PlanMaterial planMaterial = planMaterialMapper.selectById(id);
        if (validateId.equals(planMaterial.getWpiId())) {
            return planMaterial;
        }
        return null;
    }

    @Override
    public Page<PlanMaterial> list(PlanMaterialDto dto) {
        return null;
    }

    @Override
    public LambdaQueryWrapper<PlanMaterial> fuzzyQuery(PlanMaterialDto dto) {
        return null;
    }
}
